<template name="asnReceiveRFDetailInputPage">
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true" backRouterName="asnReceiveRFListPage">
			<block slot="content">ASN收货确认</block>
		</cu-custom>
		<view>
			<view class="cu-list menu-avatar">
				<view>
					<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
						<view class="title">ASN：</view>{{this.myFormData.asnCode}}
					</view>
					<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.2s'}]">
						<view class="title">物料编码：</view>{{this.myFormData.itemCode}}
					</view>
					<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.3s'}]">
						<view class="title">物料名称：</view>{{this.myFormData.itemName}}
					</view>
					<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.4s'}]">
						<view class="title">已收数量/总量：</view>{{this.myFormData.percentQty}}
					</view>
					<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.4s'}]">
						<view class="title">收货库位：</view>{{this.myFormData.receiveLoc}}
					</view>
					<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.5s'}]">
						<view class="title">托盘码：</view>{{this.myFormData.palletNo}}
					</view>
					<form >
						<view class="cu-form-group animation-slide-bottom margin-top">
							<view class="title">收货数量：</view>
							<input type="number" placeholder="请输入收货数量" name="input" v-model="myFormData.receiveQuantity"></input>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">箱号：</view>
							<input placeholder="请输入箱号" name="input" v-model="myFormData.boxNo"></input>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">生产日期：</view>
							<picker mode="date" :value="myFormData.lot01" @change="productDateChange">
								<view class="picker">
									{{lot09}}
								</view>
							</picker>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">销售单：</view>
							<input placeholder="请输入销售单" name="input" v-model="myFormData.lot02"></input>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">供应商编码：</view>
							<input placeholder="请输入供应商编码" name="input" v-model="myFormData.lot03"></input>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">ERP编码：</view>
							<input placeholder="请输入ERP编码" name="input" v-model="myFormData.lot04"></input>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">等级：</view>
							<input placeholder="请输入等级" name="input" v-model="myFormData.lot05"></input>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">档次：</view>
							<input placeholder="请输入档次" name="input" v-model="myFormData.lot06"></input>
						</view>
						<view class="cu-form-group animation-slide-bottom">
							<view class="title">SN号：</view>
							<input placeholder="请输入SN" name="input" v-model="myFormData.lot07"></input>
						</view>
						<view class="flex">
							<view class="flex-sub margin-xs radius padding">
								<view class="flex flex-direction">
									<button class="cu-btn bg-blue lg"  @click="onReiving">收货</button>
								</view>
							</view>
							<view class="flex-sub margin-xs radius padding">
								<view class="flex flex-direction">
									<button class="cu-btn bg-blue lg"  @click="onNewPallet">新托盘</button>
								</view>
							</view>
						</view>
					</form>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import crypto from '@/api/crypto.js' 
	export default {
		data() {
			return {
				searchParam:'',
				myFormData:{
					asnId:'',
					asnCode:'',
					detailId:'',
					itemCode:'',
					itemName:'',
					packageName:'',
					percentQty:'',
					customerBill:'',
					receiveLoc:'',
					totalQty:0,
					recived:0,
					palletNo:'',
					receiveQuantity:'',
					boxNo:'',
					lot01:'',
					lot02:'',
					lot03:'',
					lot04:'',
					lot05:'',
					lot06:'',
					lot07:'',
					beNewPallet:false,
				},
				lot09:'',
				initDetailInputUrl:'/pda/initReceiveDetailInputInfo',
				receiveDetailInputUrl:'/pda/receiveDetail',
			}
		},
		onLoad:function(option){
			if(!option.item){
				uni.navigateTo({
					url: '/pages/wms/asnReceiveRFListPage'
				});
				return;
			}
			const tempItem = JSON.parse(decodeURIComponent(option.item));
			this.myFormData = tempItem 
			this.initReceiveDetailInputList();
			this.getCurrentTime();
		},
		methods: {
			initReceiveDetailInputList(){
				this.$http.get(this.initDetailInputUrl,{params:{detailId:crypto.encrypt(this.myFormData.detailId)}}).then(res=>{
				  if(res.data.success){
					if(res.data.result.percentQty){
						this.myFormData.percentQty = res.data.result.percentQty;
					}
				  }
				})
			},
			getCurrentTime(){
				let myDate = new Date();
				let yy = String(myDate.getFullYear());
				let mm = String(myDate.getMonth() + 1);
				if(mm.length == 1){
					mm = "0"+mm;
				}
				let dd = String(myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate());
				let now = yy + '-' + mm + '-' + dd;
				this.lot09 = now;
			},
			productDateChange(e) {
				this.lot09 = e.detail.value
				this.myFormData.lot01 = e.detail.value
			},
			onReiving(){
				this.$http.post(this.receiveDetailInputUrl,this.myFormData).then(res=>{
					let statusCode = res.data.code;
					if (res.data.success){
						if(statusCode == 1){
							//收货完成置空输入信息
							this.myFormData.boxNo='';
							this.myFormData.receiveQuantity=''
							this.myFormData.lot01=''
							this.myFormData.lot02=''
							this.myFormData.lot03=''
							this.myFormData.lot04=''
							this.myFormData.lot05=''
							this.myFormData.lot06=''
							this.myFormData.lot07=''
							uni.navigateTo({
								url: '/pages/wms/asnReceiveRFDetailInputPage?item='+ encodeURIComponent(JSON.stringify(this.myFormData))
							});
						}else if(statusCode == 2){
							uni.navigateTo({
								url: '/pages/wms/asnReceiveRFDetailListPage?item='+ encodeURIComponent(JSON.stringify(this.myFormData))
							});
						}else if(statusCode == 3){
							uni.navigateTo({
								url: '/pages/wms/asnReceiveRFListPage'
							});
						}
					}else{
						this.$tip.error(res.data.message);
					}
				}).catch(()=>{
					this.$tip.loaded();
				});
			},
			onNewPallet(){
				//清空托盘号
				this.myFormData.palletNo='';
				//是否新托盘
				this.myFormData.beNewPallet=true
				uni.navigateTo({
					url: '/pages/wms/asnReceiveRFPalletInputPage?item='+ encodeURIComponent(JSON.stringify(this.myFormData))
				});
			}
		}
	}
</script>

